/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.unal.bioingenium.kbmed.knowledge.similarity.metrics;

import co.edu.unal.bioingenium.kbmed.knowledge.hierarchy.HierarchyService;

/**
 * 
 * @author Alejandro Riveros Cruz
 * simwp(p1,p2)=2*N3/(N1+N2+2*N3)
 * Where:
 *  p3 = leastCommon superconpcept of p1 and p2
 *  N1 = path length from p1 to p3
 *  N2 = path length from p2 to p3
 *  N3 = path length from p3 to root
 * Verbs semantics and lexical selection
 * by: Zhibiao Wu, Martha Palmer
 */
public class WP implements SemanticSimilarity {

    private HierarchyService graphManager;

    /**
     * 
     */
    public WP() {
        this.graphManager = HierarchyService.getInstance();
    }

    /**
     * 
     * @param conceptId1
     * @param conceptId2
     * @param category
     * @return
     */
    @Override
    public float getSimilarity(String conceptId1, String conceptId2, String category) {
        int N1, N2, N3;
        String p3Id = graphManager.getLeastCommonSubsummer(conceptId1, conceptId2, category);
        N1 = graphManager.getShortestPath(conceptId1, p3Id, category).size();
        N2 = graphManager.getShortestPath(conceptId2, p3Id, category).size();
        N3 = graphManager.getPathToRoot(p3Id, category).size() + 1;
        return (float) (2 * N3) / (float) (N1 + N2 + 2 * N3);
    }
}
